package com.larry.mr.order;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @ProjectName map-reduce
 * @Author larry
 * @Date 9:52 2022/4/7
 * @Description TODO
 **/
public class OrderBean implements WritableComparable<OrderBean> {

    private int order_id;
    private double price;

    public OrderBean() {

    }

    public OrderBean(int order_id, double price) {
        this.order_id = order_id;
        this.price = price;
    }

    @Override
    public String toString() {
        return order_id + "\t" + price;
    }

    @Override
    public int compareTo(OrderBean orderBean) {

        int res;
        if (order_id > orderBean.getOrder_id()){
            res = 1;
        }else if (order_id < orderBean.getOrder_id()){
            res = -1;
        }else {
            if (price > orderBean.getPrice()){
                res = -1;
            }else if (price < orderBean.getPrice()){
                res = 1;
            }else {
                res = 0;
            }
        }

        return res;
    }

    @Override
    public void write(DataOutput out) throws IOException {

        out.writeInt(order_id);
        out.writeDouble(price);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        order_id = in.readInt();
        price = in.readDouble();
    }

    public int getOrder_id() {
        return order_id;
    }

    public void setOrder_id(int order_id) {
        this.order_id = order_id;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}
